package com.cykj.controller;

import com.cykj.dto.ResponseDTO;
import com.cykj.feign.OrderControllerFeign;
import com.cykj.service.IUserService;
import com.cykj.utils.JwtUtil;
import com.cykj.vo.OrderVO;
import com.cykj.vo.UserVO;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * @author 王宇
 * @CreateTime: 2025-07-22  15:24
 * @BelongsProject: jd_seckill
 * @BelongsPackage: com.cykj.controller
 * @description 用户管理
 */
@RequestMapping("/jd/cli/user")
@RestController
@RefreshScope
public class UserController {
    @Autowired
    private IUserService userService;

    @Autowired
    private OrderControllerFeign orderControllerFeign;

    @PostMapping("/login")
    public ResponseDTO login(@RequestBody UserVO userVO) {
        return userService.login(userVO);
    }

    @PostMapping("/register")
    public ResponseDTO register(@RequestBody UserVO userVO) {
        return userService.register(userVO);
    }

    @GetMapping("/getOrderList")
    public ResponseDTO getOrderList(OrderVO orderVO) {
        return orderControllerFeign.getOrderList(orderVO);
    }

    @GetMapping("/getUserToToken")
    public ResponseDTO getUserToToken(String token) {
        Claims claims = JwtUtil.parseJWT(token);
        return ResponseDTO.success("token解析成功", claims);
    }
}
